package Model;

/**
 * Contains the map in a given game
 * -Created Class(Mar 14,2011)
 * Samual Martelli
 * </pre>
 */
@SuppressWarnings({ "hiding", "unchecked" })
public class MazeMap<Point,Integer>{
	//number of cells equal to 1 + Map size squared
	public final int NUM_OF_CELLS = (int) Math.pow((Maze.MAP_SIZE+1),2);
	private MazeCell<Point,Integer>[] mapValues;
	
	public MazeMap(){
		mapValues =  new MazeCell[NUM_OF_CELLS];
	}
	/**
	 * Get the mazeSpot of the cell and return its value
	 * -Created Method(Mar 14,2011)
	 * Samual Martelli
	 * </pre>
	 */
	@SuppressWarnings("unchecked")
	public Integer get(Point mazeSpot) {
		for (int i = 0; i < NUM_OF_CELLS; i++) {
			if (mapValues[i] != null) {
				if (mapValues[i].getKey().equals(mazeSpot)) {
					return (Integer) (mapValues[i].getValue());
				}
			}
			//is null create a new cell
			else{
				mapValues[i] =  new MazeCell(mazeSpot,Maze.EMPTY_SPACE);
				return (Integer) (mapValues[i].getValue());
			}
		}
		return null;
	}
	
	/**
	 * Put a newValue into the current position of the cell at mazeSpot
	 * -Created Class(Mar 14,2011)
	 * Samual Martelli
	 * </pre>
	 */
	public void put(Point mazeSpot, Integer newValue) {
		for (int i = 0; i < NUM_OF_CELLS; i++) {
			if(mapValues[i] != null){
				if (mapValues[i].getKey().equals(mazeSpot)) {
					mapValues[i].setValue(newValue);
				}
			}
			else{
				mapValues[i] =  new MazeCell(mazeSpot,newValue);
			}
		}
		
	}	
}
